﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using MTC.Common.Configuration;
using MTC.Common.DTO;

namespace MTC.DataAccess
{
    public static class DriverDataAccess
    {
        public static List<Driver> GetDrivers()
        {
            List<Driver> listOfDrivers = new List<Driver>();

            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            if (db != null)
            {
                const string sqlCommandText = "spDriver_GetAllDrivers";
                using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
                {

                    using (SqlDataReader dataReader = db.ExecuteReader(sqlCommand) as SqlDataReader)
                    {
                        Driver entity;

                        if (dataReader != null)
                            while (dataReader.Read())
                            {
                                entity = new Driver();
                                entity.DriverId = Convert.ToInt32(dataReader["DriverId"]);

                                entity.Rates = GetDriverRate(entity.DriverId);
                                //entity.Comments = GetDriverComment(entity.DriverId);

                                if (!Convert.IsDBNull(dataReader["Title"]))
                                    entity.Title = Convert.ToString(dataReader["Title"]);
                                if (!Convert.IsDBNull(dataReader["FirstName"]))
                                    entity.FirstName = Convert.ToString(dataReader["FirstName"]);
                                if (!Convert.IsDBNull(dataReader["LastName"]))
                                    entity.LastName = Convert.ToString(dataReader["LastName"]);
                                if (!Convert.IsDBNull(dataReader["Street1"]))
                                    entity.Street1 = Convert.ToString(dataReader["Street1"]);
                                if (!Convert.IsDBNull(dataReader["Street2"]))
                                    entity.Street2 = Convert.ToString(dataReader["Street2"]);
                                if (!Convert.IsDBNull(dataReader["Suburb"]))
                                    entity.Suburb = Convert.ToString(dataReader["Suburb"]);
                                if (!Convert.IsDBNull(dataReader["State"]))
                                    entity.State = Convert.ToString(dataReader["State"]);
                                if (!Convert.IsDBNull(dataReader["Postcode"]))
                                    entity.Postcode = Convert.ToString(dataReader["Postcode"]);
                                if (!Convert.IsDBNull(dataReader["Phone"]))
                                    entity.Phone = Convert.ToString(dataReader["Phone"]);
                                if (!Convert.IsDBNull(dataReader["Mobile1"]))
                                    entity.Mobile1 = Convert.ToString(dataReader["Mobile1"]);
                                if (!Convert.IsDBNull(dataReader["Mobile2"]))
                                    entity.Mobile2 = Convert.ToString(dataReader["Mobile2"]);
                                if (!Convert.IsDBNull(dataReader["Licience"]))
                                    entity.Licience = Convert.ToString(dataReader["Licience"]);
                                if (!Convert.IsDBNull(dataReader["DriverLicienceExpiry"]))
                                    entity.DriverLicienceExpiry = Convert.ToDateTime(dataReader["DriverLicienceExpiry"]);
                                if (!Convert.IsDBNull(dataReader["TaxiLicience"]))
                                    entity.TaxiLicience = Convert.ToString(dataReader["TaxiLicience"]);
                                if (!Convert.IsDBNull(dataReader["ABN"]))
                                    entity.ABN = Convert.ToString(dataReader["ABN"]);
                                if (!Convert.IsDBNull(dataReader["DateOfBirth"]))
                                    entity.DateOfBirth = Convert.ToDateTime(dataReader["DateOfBirth"]);
                                if (!Convert.IsDBNull(dataReader["CommencementDate"]))
                                    entity.CommencementDate = Convert.ToDateTime(dataReader["CommencementDate"]);
                                if (!Convert.IsDBNull(dataReader["Nickname"]))
                                    entity.Nickname = Convert.ToString(dataReader["Nickname"]);
                                if (!Convert.IsDBNull(dataReader["TaxiLicienceExpiry"]))
                                    entity.TaxiLicienceExpiry = Convert.ToDateTime(dataReader["TaxiLicienceExpiry"]);
                                if (!Convert.IsDBNull(dataReader["ETagNumber"]))
                                    entity.ETagNumber = Convert.ToString(dataReader["ETagNumber"]);
                                if (!Convert.IsDBNull(dataReader["ETagAccount"]))
                                    entity.ETagAccount = Convert.ToString(dataReader["ETagAccount"]);
                                if (!Convert.IsDBNull(dataReader["Active"]))
                                    entity.Active = Convert.ToBoolean(dataReader["Active"]);
                                if (!Convert.IsDBNull(dataReader["Gender"]))
                                    entity.Gender = Convert.ToInt32(dataReader["Gender"]);

                                listOfDrivers.Add(entity);
                            }
                    }
                }
            }
            return listOfDrivers;
            
        }

        private static List<DriverComment> GetDriverComment(int driverid)
        {
            List<DriverComment> listOfDriverComments = new List<DriverComment>();

            DriverComment entity = null;

            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            if (db != null)
            {
                const string sqlCommandText = "spDriver_GetDriverComment";
                using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
                {
                    db.AddInParameter(sqlCommand, "@DriverId", DbType.Int32, driverid);

                    using (SqlDataReader dataReader = db.ExecuteReader(sqlCommand) as SqlDataReader)
                    {

                        if (dataReader.HasRows)
                        {
                            while (dataReader.Read())
                            {
                                entity = new DriverComment();

                                if (!Convert.IsDBNull(dataReader["DriverCommentId"]))
                                    entity.DriverCommentId = Convert.ToInt32(dataReader["DriverCommentId"]);

                                if (!Convert.IsDBNull(dataReader["DriverId"]))
                                    entity.DriverId = Convert.ToInt32(dataReader["DriverId"]);
                                if (!Convert.IsDBNull(dataReader["Comment"]))
                                    entity.Comment = Convert.ToString(dataReader["Comment"]);
                                if (!Convert.IsDBNull(dataReader["CommentDate"]))
                                    entity.CommentDate = Convert.ToDateTime(dataReader["CommentDate"]);

                                listOfDriverComments.Add(entity);
                            }
                        }
                    }
                }
            }
            return listOfDriverComments;
        }

        private static DriverRate GetDriverRate(int driverid)
        {
            DriverRate entity = null;

            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            if (db != null)
            {
                const string sqlCommandText = "spDriver_GetDriverRate";
                using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
                {
                    db.AddInParameter(sqlCommand, "@DriverId", DbType.Int32, driverid);

                    using (SqlDataReader dataReader = db.ExecuteReader(sqlCommand) as SqlDataReader)
                    {

                        if (dataReader.HasRows)
                        {
                            dataReader.Read();
                            entity = new DriverRate();

                            
                            if (!Convert.IsDBNull(dataReader["DriverRateId"]))
                                entity.DriverRateId = Convert.ToInt32(dataReader["DriverRateId"]);

                            if (!Convert.IsDBNull(dataReader["DriverId"]))
                                entity.DriverId = Convert.ToInt32(dataReader["DriverId"]);

                                if (!Convert.IsDBNull(dataReader["MonDayRate"]))
                                    entity.MonDayRate = Convert.ToString(dataReader["MonDayRate"]);
                                if (!Convert.IsDBNull(dataReader["MonNightRate"]))
                                    entity.MonNightRate = Convert.ToString(dataReader["MonNightRate"]);
                                if (!Convert.IsDBNull(dataReader["TuesDayRate"]))
                                    entity.TuesDayRate = Convert.ToString(dataReader["TuesDayRate"]);
                                if (!Convert.IsDBNull(dataReader["TuesNightRate"]))
                                    entity.TuesNightRate = Convert.ToString(dataReader["TuesNightRate"]);
                                if (!Convert.IsDBNull(dataReader["WedDayRate"]))
                                    entity.WedDayRate = Convert.ToString(dataReader["WedDayRate"]);
                                if (!Convert.IsDBNull(dataReader["WedNightRate"]))
                                    entity.WedNightRate = Convert.ToString(dataReader["WedNightRate"]);
                                if (!Convert.IsDBNull(dataReader["ThursDayRate"]))
                                    entity.ThursDayRate = Convert.ToString(dataReader["ThursDayRate"]);
                                if (!Convert.IsDBNull(dataReader["ThursNightRate"]))
                                    entity.ThursNightRate = Convert.ToString(dataReader["ThursNightRate"]);
                                if (!Convert.IsDBNull(dataReader["FriDayRate"]))
                                    entity.FriDayRate = Convert.ToString(dataReader["FriDayRate"]);
                                if (!Convert.IsDBNull(dataReader["FriNightRate"]))
                                    entity.FriNightRate = Convert.ToString(dataReader["FriNightRate"]);
                                if (!Convert.IsDBNull(dataReader["SatDayRate"]))
                                    entity.SatDayRate = Convert.ToString(dataReader["SatDayRate"]);
                                if (!Convert.IsDBNull(dataReader["SatNightRate"]))
                                    entity.SatNightRate = Convert.ToString(dataReader["SatNightRate"]);
                                if (!Convert.IsDBNull(dataReader["SunDayRate"]))
                                    entity.SunDayRate = Convert.ToString(dataReader["SunDayRate"]);
                                if (!Convert.IsDBNull(dataReader["SunNightRate"]))
                                    entity.SunNightRate = Convert.ToString(dataReader["SunNightRate"]);
                            }
                    }
                }
            }
            return entity;

        }

        public static int AddDriver(Driver driver)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommand = "spDriver_InsertDriver";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

            db.AddInParameter(dbCommand, "@Title", DbType.String, driver.Title);
            db.AddInParameter(dbCommand, "@FirstName", DbType.String, driver.FirstName);
            db.AddInParameter(dbCommand, "@LastName", DbType.String, driver.LastName);
            db.AddInParameter(dbCommand, "@Street1", DbType.String, driver.Street1);
            db.AddInParameter(dbCommand, "@Street2", DbType.String, driver.Street2);
            db.AddInParameter(dbCommand, "@Suburb", DbType.String, driver.Suburb);
            db.AddInParameter(dbCommand, "@State", DbType.String, driver.State);
            db.AddInParameter(dbCommand, "@Postcode", DbType.String, driver.Postcode);
            db.AddInParameter(dbCommand, "@Phone", DbType.String, driver.Phone);
            db.AddInParameter(dbCommand, "@Mobile1", DbType.String, driver.Mobile1);
            db.AddInParameter(dbCommand, "@Mobile2", DbType.String, driver.Mobile2);
            db.AddInParameter(dbCommand, "@Licience", DbType.String, driver.Licience);
            db.AddInParameter(dbCommand, "@DriverLicienceExpiry", DbType.DateTime, driver.DriverLicienceExpiry);
            db.AddInParameter(dbCommand, "@TaxiLicience", DbType.String, driver.TaxiLicience);
            db.AddInParameter(dbCommand, "@ABN", DbType.String, driver.ABN);
            db.AddInParameter(dbCommand, "@DateOfBirth", DbType.DateTime, driver.DateOfBirth);
            db.AddInParameter(dbCommand, "@CommencementDate", DbType.DateTime, driver.CommencementDate);
            db.AddInParameter(dbCommand, "@Nickname", DbType.String, driver.Nickname);
            db.AddInParameter(dbCommand, "@TaxiLicienceExpiry", DbType.DateTime, driver.TaxiLicienceExpiry);
            db.AddInParameter(dbCommand, "@ETagNumber", DbType.String, driver.ETagNumber);
            db.AddInParameter(dbCommand, "@ETagAccount", DbType.String, driver.ETagAccount);
            db.AddInParameter(dbCommand, "@Gender", DbType.String, driver.Gender);

            db.AddInParameter(dbCommand, "@MonDayRate", DbType.String, driver.Rates.MonDayRate);
            db.AddInParameter(dbCommand, "@MonNightRate", DbType.String, driver.Rates.MonNightRate);
            db.AddInParameter(dbCommand, "@TuesDayRate", DbType.String, driver.Rates.TuesDayRate);
            db.AddInParameter(dbCommand, "@TuesNightRate", DbType.String, driver.Rates.TuesNightRate);
            db.AddInParameter(dbCommand, "@WedDayRate", DbType.String, driver.Rates.WedDayRate);
            db.AddInParameter(dbCommand, "@WedNightRate", DbType.String, driver.Rates.WedNightRate);
            db.AddInParameter(dbCommand, "@ThursDayRate", DbType.String, driver.Rates.ThursDayRate);
            db.AddInParameter(dbCommand, "@ThursNightRate", DbType.String, driver.Rates.ThursNightRate);
            db.AddInParameter(dbCommand, "@FriDayRate", DbType.String, driver.Rates.FriDayRate);
            db.AddInParameter(dbCommand, "@FriNightRate", DbType.String, driver.Rates.FriNightRate);
            db.AddInParameter(dbCommand, "@SatDayRate", DbType.String, driver.Rates.SatDayRate);
            db.AddInParameter(dbCommand, "@SatNightRate", DbType.String, driver.Rates.SatNightRate);
            db.AddInParameter(dbCommand, "@SunDayRate", DbType.String, driver.Rates.SunDayRate);
            db.AddInParameter(dbCommand, "@SunNightRate", DbType.String, driver.Rates.SunNightRate);



            return db.ExecuteNonQuery(dbCommand);

        }

        public static bool UpdateDriver(Driver driver)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommandText = "spDriver_UpdateDriver";
            int result;
            using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
            {
                db.AddInParameter(sqlCommand, "@DriverId", DbType.Int32, driver.DriverId);
                db.AddInParameter(sqlCommand, "@Title", DbType.String, driver.Title);
                db.AddInParameter(sqlCommand, "@FirstName", DbType.String, driver.FirstName);
                db.AddInParameter(sqlCommand, "@LastName", DbType.String, driver.LastName);
                db.AddInParameter(sqlCommand, "@Street1", DbType.String, driver.Street1);
                db.AddInParameter(sqlCommand, "@Street2", DbType.String, driver.Street2);
                db.AddInParameter(sqlCommand, "@Suburb", DbType.String, driver.Suburb);
                db.AddInParameter(sqlCommand, "@State", DbType.String, driver.State);
                db.AddInParameter(sqlCommand, "@Postcode", DbType.String, driver.Postcode);
                db.AddInParameter(sqlCommand, "@Phone", DbType.String, driver.Phone);
                db.AddInParameter(sqlCommand, "@Mobile1", DbType.String, driver.Mobile1);
                db.AddInParameter(sqlCommand, "@Mobile2", DbType.String, driver.Mobile2);
                db.AddInParameter(sqlCommand, "@Licience", DbType.String, driver.Licience);
                db.AddInParameter(sqlCommand, "@DriverLicienceExpiry", DbType.DateTime, driver.DriverLicienceExpiry);
                db.AddInParameter(sqlCommand, "@TaxiLicience", DbType.String, driver.TaxiLicience);
                db.AddInParameter(sqlCommand, "@ABN", DbType.String, driver.ABN);
                db.AddInParameter(sqlCommand, "@DateOfBirth", DbType.DateTime, driver.DateOfBirth);
                db.AddInParameter(sqlCommand, "@CommencementDate", DbType.DateTime, driver.CommencementDate);
                db.AddInParameter(sqlCommand, "@Nickname", DbType.String, driver.Nickname);
                db.AddInParameter(sqlCommand, "@TaxiLicienceExpiry", DbType.DateTime, driver.TaxiLicienceExpiry);
                db.AddInParameter(sqlCommand, "@ETagNumber", DbType.String, driver.ETagNumber);
                db.AddInParameter(sqlCommand, "@ETagAccount", DbType.String, driver.ETagAccount);
                db.AddInParameter(sqlCommand, "@Gender", DbType.Int32, driver.Gender);

                db.AddInParameter(sqlCommand, "@MonDayRate", DbType.String, driver.Rates.MonDayRate);
                db.AddInParameter(sqlCommand, "@MonNightRate", DbType.String, driver.Rates.MonNightRate);
                db.AddInParameter(sqlCommand, "@TuesDayRate", DbType.String, driver.Rates.TuesDayRate);
                db.AddInParameter(sqlCommand, "@TuesNightRate", DbType.String, driver.Rates.TuesNightRate);
                db.AddInParameter(sqlCommand, "@WedDayRate", DbType.String, driver.Rates.WedDayRate);
                db.AddInParameter(sqlCommand, "@WedNightRate", DbType.String, driver.Rates.WedNightRate);
                db.AddInParameter(sqlCommand, "@ThursDayRate", DbType.String, driver.Rates.ThursDayRate);
                db.AddInParameter(sqlCommand, "@ThursNightRate", DbType.String, driver.Rates.ThursNightRate);
                db.AddInParameter(sqlCommand, "@FriDayRate", DbType.String, driver.Rates.FriDayRate);
                db.AddInParameter(sqlCommand, "@FriNightRate", DbType.String, driver.Rates.FriNightRate);
                db.AddInParameter(sqlCommand, "@SatDayRate", DbType.String, driver.Rates.SatDayRate);
                db.AddInParameter(sqlCommand, "@SatNightRate", DbType.String, driver.Rates.SatNightRate);
                db.AddInParameter(sqlCommand, "@SunDayRate", DbType.String, driver.Rates.SunDayRate);
                db.AddInParameter(sqlCommand, "@SunNightRate", DbType.String, driver.Rates.SunNightRate);

                result = db.ExecuteNonQuery(sqlCommand);
            }
            

            return result > 0 ? true : false;

    
        }

        public static bool DeleteDriver(int DriverId)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommandText = "spDriver_DeleteDriver";
            int result;
            using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
            {
                db.AddInParameter(sqlCommand, "@DriverID", DbType.Int32, DriverId);
                result = db.ExecuteNonQuery(sqlCommand);
            }

            return result > 0 ? true : false;
        
        }

        public static Driver GetDriver(int DriverId)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            string sqlCommand = "spDriver_GetDriver";

            using (SqlCommand dbCommand = db.GetStoredProcCommand(sqlCommand) as SqlCommand)
            {
                db.AddInParameter(dbCommand, "DriverId", DbType.Int32, DriverId);

                using (SqlDataReader data = db.ExecuteReader(dbCommand) as SqlDataReader)
                {
                    if (data.HasRows && data.Read())
                    {
                        MTC.Common.DTO.Driver driver = new MTC.Common.DTO.Driver();

                        driver.DriverId = Convert.ToInt32(data["DriverId"]);
                        driver.Rates = GetDriverRate(driver.DriverId);
                        driver.Comments = GetDriverComment(driver.DriverId);
                        if (!Convert.IsDBNull(data["Title"]))
                            driver.Title = Convert.ToString(data["Title"]);
                        if (!Convert.IsDBNull(data["FirstName"]))
                            driver.FirstName = Convert.ToString(data["FirstName"]);
                        if (!Convert.IsDBNull(data["LastName"]))
                            driver.LastName = Convert.ToString(data["LastName"]);
                        if (!Convert.IsDBNull(data["Street1"]))
                            driver.Street1 = Convert.ToString(data["Street1"]);
                        if (!Convert.IsDBNull(data["Street2"]))
                            driver.Street2 = Convert.ToString(data["Street2"]);
                        if (!Convert.IsDBNull(data["Suburb"]))
                            driver.Suburb = Convert.ToString(data["Suburb"]);
                        if (!Convert.IsDBNull(data["State"]))
                            driver.State = Convert.ToString(data["State"]);
                        if (!Convert.IsDBNull(data["Postcode"]))
                            driver.Postcode = Convert.ToString(data["Postcode"]);
                        if (!Convert.IsDBNull(data["Phone"]))
                            driver.Phone = Convert.ToString(data["Phone"]);
                        if (!Convert.IsDBNull(data["Mobile1"]))
                            driver.Mobile1 = Convert.ToString(data["Mobile1"]);
                        if (!Convert.IsDBNull(data["Mobile2"]))
                            driver.Mobile2 = Convert.ToString(data["Mobile2"]);
                        if (!Convert.IsDBNull(data["Licience"]))
                            driver.Licience = Convert.ToString(data["Licience"]);
                        if (!Convert.IsDBNull(data["DriverLicienceExpiry"]))
                            driver.DriverLicienceExpiry = Convert.ToDateTime(data["DriverLicienceExpiry"]);
                        if (!Convert.IsDBNull(data["TaxiLicience"]))
                            driver.TaxiLicience = Convert.ToString(data["TaxiLicience"]);
                        if (!Convert.IsDBNull(data["ABN"]))
                            driver.ABN = Convert.ToString(data["ABN"]);
                        if (!Convert.IsDBNull(data["DateOfBirth"]))
                            driver.DateOfBirth = Convert.ToDateTime(data["DateOfBirth"]);
                        if (!Convert.IsDBNull(data["CommencementDate"]))
                            driver.CommencementDate = Convert.ToDateTime(data["CommencementDate"]);
                        if (!Convert.IsDBNull(data["Nickname"]))
                            driver.Nickname = Convert.ToString(data["Nickname"]);
                        if (!Convert.IsDBNull(data["TaxiLicienceExpiry"]))
                            driver.TaxiLicienceExpiry = Convert.ToDateTime(data["TaxiLicienceExpiry"]);
                        if (!Convert.IsDBNull(data["ETagNumber"]))
                            driver.ETagNumber = Convert.ToString(data["ETagNumber"]);
                        if (!Convert.IsDBNull(data["ETagAccount"]))
                            driver.ETagAccount = Convert.ToString(data["ETagAccount"]);
                        if (!Convert.IsDBNull(data["Active"]))
                            driver.Active = Convert.ToBoolean(data["Active"]);
                        if (!Convert.IsDBNull(data["Gender"]))
                            driver.Gender = Convert.ToInt32(data["Gender"]);


                        return driver;
                    }
                }
            }
            return null;
        }


        public static List<DriverComment> GetDriverComments(int DriverId)
        {
            return GetDriverComment(DriverId);
        }

        public static bool UpdateDriverComment(int DriverCommentId, int DriverId, string Comment, DateTime CommentDate)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommandText = "spDriver_UpdateComment";
            int result;
            using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
            {

                db.AddInParameter(sqlCommand, "@DriverCommentId", DbType.Int32, DriverCommentId);
                db.AddInParameter(sqlCommand, "@DriverId", DbType.Int32, DriverId);
                db.AddInParameter(sqlCommand, "@CommentDate", DbType.DateTime, CommentDate);
                db.AddInParameter(sqlCommand, "@Comment", DbType.String, Comment);

                result = db.ExecuteNonQuery(sqlCommand);
            }


            return result > 0 ? true : false;

        }

        public static int AddComments(int DriverId, DateTime CommentDate, string Comment)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommand = "spDriver_InsertComment";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

            db.AddInParameter(dbCommand, "@DriverId", DbType.Int32, DriverId);
            db.AddInParameter(dbCommand, "@CommentDate", DbType.DateTime, CommentDate);
            db.AddInParameter(dbCommand, "@Comment", DbType.String, Comment);

            return db.ExecuteNonQuery(dbCommand);
        }

        public static bool DeleteComment(int DriverCommentId)
        {
            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);

            const string sqlCommandText = "spDriver_DeleteComment";
            int result;
            using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
            {
                db.AddInParameter(sqlCommand, "@DriverCommentId", DbType.Int32, DriverCommentId);
                result = db.ExecuteNonQuery(sqlCommand);
            }

            return result > 0 ? true : false;
        }
    }
}
